//
//  ProfileInfoViewController.m
//  SmartWatch
//
//  Created by zwj on 2022/11/22.
//

@interface QrcodeView : UIView

@end

@implementation QrcodeView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = COLOR_4;
        self.layer.cornerRadius = 15.0;
        self.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
        
        MyLinearLayout *root = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
        root.myHorzMargin = 0;
        root.padding = UIEdgeInsetsMake(40, 15, 0, 15);
        root.gravity = MyGravity_Horz_Center;
        root.subviewVSpace = 10;
        [self addSubview:root];
        
        UIImageView *avatar = [[UIImageView alloc]initWithImage:UIImageMake(@"avatar")];
        avatar.mySize = CGSizeMake(64, 64);
        [root addSubview:avatar];
        
        
        UILabel *name = [UILabel createLabelText:@"爱笑的小暖" font:UIFontMake(16) textColor:COLOR1515];
        name.mySize = kAutoSize;
        [root addSubview:name];
        
        UIImageView *qrcode = [[UIImageView alloc]initWithImage:[self setupQRCodeImage:@"张文进"]];
        qrcode.mySize = CGSizeMake(180, 180);
        qrcode.myTop = 30;
        [root addSubview:qrcode];
        
    }
    return self;
}

- (UIImage *)setupQRCodeImage:(NSString *)url
{
    NSData *data = [url dataUsingEncoding:NSUTF8StringEncoding];
    CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
    [filter setValue:data forKey:@"inputMessage"];
    [filter setValue:@"H" forKey:@"inputCorrectionLevel"];
    CIImage *image = filter.outputImage;
    
    return [UIImage imageWithCIImage:image];
}


@end

#import "ProfileInfoViewController.h"
#import "QDSingleImagePickerPreviewViewController.h"

@interface ProfileInfoViewController ()<TZImagePickerControllerDelegate>

@property(nonatomic,strong) UIImageView *avatarImage;
@end

@implementation ProfileInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"个人资料";
    
    FlexFrameView *view = [[FlexFrameView alloc]initWithFlex:@"ProfileInfoViewController" Frame:CGRectMake(0, NavigationContentTop, kScreenWidth, kScreenHeight - NavigationContentTop) Owner:self];
    [self.view addSubview:view];
    
    
}
#pragma mark - 选择头像
- (void)selectAlum {
    TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 columnNumber:3 delegate:self pushPhotoPickerVc:YES];

    imagePickerVc.iconThemeColor = [UIColor colorWithRed:31 / 255.0 green:185 / 255.0 blue:34 / 255.0 alpha:1.0];
    imagePickerVc.showPhotoCannotSelectLayer = YES;
    imagePickerVc.cannotSelectLayerColor = [[UIColor whiteColor] colorWithAlphaComponent:0.8];
    // 3. 设置是否可以选择视频/图片/原图
    imagePickerVc.allowPickingVideo = NO;
    imagePickerVc.allowPickingImage = YES;
    imagePickerVc.allowPickingOriginalPhoto = YES;
    imagePickerVc.statusBarStyle = UIStatusBarStyleLightContent;
       // 设置是否显示图片序号
    imagePickerVc.showSelectedIndex = YES;
    
    imagePickerVc.allowCrop = YES;
    imagePickerVc.needCircleCrop = YES;
    imagePickerVc.circleCropRadius = kScreenWidth/2;
    imagePickerVc.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:imagePickerVc animated:YES completion:nil];
}


- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto infos:(NSArray<NSDictionary *> *)infos {
    UIImage *resultImage = photos.firstObject;
    
    self.avatarImage.image = resultImage;
    
}


// 昵称
- (void)nickNameClick {
    
    QMUIAlertController *alertController = [QMUIAlertController alertControllerWithTitle:@"昵称" message:@"" preferredStyle:QMUIAlertControllerStyleAlert];
    [alertController addAction:[QMUIAlertAction actionWithTitle:@"确定" style:QMUIAlertActionStyleDestructive handler:NULL]];
    [alertController addCancelAction];
    [alertController addTextFieldWithConfigurationHandler:^(QMUITextField * _Nonnull textField) {
        textField.placeholder = @"请输入昵称";
    }];
    [alertController showWithAnimated:YES];
}

// 性别
- (void)selectSex {
    [BRStringPickerView showPickerWithTitle:@"请选择性别" dataSourceArr:@[@"男",@"女"] selectIndex:0 resultBlock:^(BRResultModel * _Nullable resultModel) {
            
    }];
}

// 选择生日
- (void)selectBrithday {
    [BRDatePickerView showDatePickerWithMode:BRDatePickerModeYMD title:@"请选择生日" selectValue:@"2000-01-01" resultBlock:^(NSDate * _Nullable selectDate, NSString * _Nullable selectValue) {
            
    }];
}

//选择身高
- (void)selectHeight {
    NSMutableArray *arr = @[].mutableCopy;
    NSInteger first = 150;
    for (int i = 0; i < 11; i++) {
        [arr addObject:FormatString(@"%ldcm",first)];
        first+= 5;
    }
    [BRStringPickerView showPickerWithTitle:@"身高修改" dataSourceArr:arr.copy selectIndex:0 isAutoSelect:NO resultBlock:^(BRResultModel * _Nullable resultModel) {
        
    }];
}

// 选择体重
- (void)selectWeight {
    NSMutableArray *arr = @[].mutableCopy;
    NSInteger first = 40;
    for (int i = 0; i < 13; i++) {
        [arr addObject:FormatString(@"%ldkg",first)];
        first+= 5;
    }
    [BRStringPickerView showPickerWithTitle:@"体重修改" dataSourceArr:arr.copy selectIndex:0 isAutoSelect:NO resultBlock:^(BRResultModel * _Nullable resultModel) {
    }];
}


// 二维码
- (void)qrcodeClick {
    QrcodeView *resultView = [[QrcodeView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth , 400)];
    self.zh_popupController = [zhPopupController new];
    self.zh_popupController.layoutType = zhPopupLayoutTypeBottom;
    self.zh_popupController.allowPan = NO;
    self.zh_popupController.maskAlpha = 0.7;
    [self.zh_popupController presentContentView:resultView];
}

@end
